﻿using System;

namespace Streaming_Service.Web {
    using System.IO;

    using Streaming_Service.Media;
    using Streaming_Service.Web.Helpers;

    public partial class thumb : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            Response.Clear();

            var id = RequestFunc.GetQueryStringInt(Request, "vid", 0);
            var fileToTransmit = Request.PhysicalApplicationPath + @"Web\Media\Thumbs\no_id.jpg";

            if(id > 0) {
                if(MediaFunc.ThumbFolderExists(id)) {
                    var thumbPath = MediaFunc.GetThumbPath(id);
                    if (!string.IsNullOrEmpty(thumbPath) && File.Exists(thumbPath)) {
                        fileToTransmit = thumbPath;
                    }else {
                        fileToTransmit = Request.PhysicalApplicationPath + @"Web\Media\Thumbs\thumb_no_avail.jpg";
                    }
                }else {
                    fileToTransmit = Request.PhysicalApplicationPath + @"Web\Media\Thumbs\invalid_id.jpg";
                }
            }
            Response.ContentType = MediaFunc.GetContentType(fileToTransmit);
            Response.TransmitFile(fileToTransmit);
        }
    }
}